// 地址管理API服务
import request from "@/common/utils/request.js";

const BASE_URL = "/api/shopping-cart";

// 添加商品到购物车
export const createCart = (data) => {
  return request({
    url: BASE_URL+'/add',
    method: "POST",
    data: {
      customerId: data.customerId,
      quantity: data.quantity,
      productId: data.productId,
    },
  });
};

// 查询购物车列表
export const getCartList = (customerId) => {
  return request({
    url: `${BASE_URL}/list/${customerId}`,
    method: "GET",
    data: {
      customerId: customerId,
    },
  });
};

// 获取购物车商品数据量
export const getCartCount = (customerId) => {
  return request({
    url: `${BASE_URL}/count/${customerId}`,
    method: "GET",
  });
};

// 更新购物车商品
export const updateCart = (id, data) => {
  return request({
    url: `${BASE_URL}/${id}`,
    method: "PATCH",
    data,
  });
};

// 删除购物车商品
export const deleteCart = (id) => {
  return request({
    url: `${BASE_URL}/${id}`,
    method: "DELETE",
  });
};

// 清空购物车
export const deleteAllCart = (customerId) => {
  return request({
    url: `${BASE_URL}/clear/${customerId}`,
    method: "DELETE",
    data: {
      customerId: customerId,
    },
  });
};

// 批量删除购物车商品
export const deleteCartList = (customerId, data) => {
  return request({
    url: `${BASE_URL}/batch-delete/${customerId}`,
    method: "DELETE",
    data: data,
  });
};

// 商品详情